<template>
	<view class="home">
		<barHeight></barHeight>
		<Page :items="items" />
		<zero-back-top :scrollTop="scrollTop"></zero-back-top>
		<sa-hover-menu @init="gethomedata"></sa-hover-menu>
		<sa-hover-menu2></sa-hover-menu2>
		<view class='firstBox' v-if='firstShow'>
			<image class="firstImg" :src="firstUrl"></image>
			<view class="firstImgTime">
				{{firstTime}}
			</view>
			<view class="firstNext" @click='hidefist'>
				跳过
			</view>
		</view>
	</view>
</template>

<script>
	import saHoverMenu from '../../components/sa-hover-menu/sa-hover-menu.vue';
	import saHoverMenu2 from '../../components/sa-hover-menu2/sa-hover-menu2.vue';
	import Page from '@/components/page'
	export default {
		components: {
			Page,
			saHoverMenu,
			saHoverMenu2
		},
		data() {
			return {
				items: [],
				scrollTop: 0,
				firstShow: false,
				firstTime: ''
			}
		},
		onPullDownRefresh() {
			this.gethomedata()
		},
		onLoad() {
			let token = uni.getStorageSync('token') || ''
			if (token == '') {
				uni.clearStorageSync();
				uni.setStorageSync('lang', 'en');
				uni.reLaunch({
					url: '/pages/login/login'
				})
			}
			this.getmask()
			this.address()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		methods: {
			hidefist(){
				this.firstShow = false
				uni.showTabBar()
			},
			getmask() {
				const params = {
					map: 'applet_popup_get'
				}
				this.$Request({
					method: 'GET',
					data: params
				}).then(res => {
					if (res.data.ec == 200) {
						this.firstUrl = 'https://dongya.hualin688.com' + res.data.data.info.asi_path
						this.firstTime = res.data.data.info.asi_time
						this.firstShow = true
						if (this.firstShow) {
							var intTime = setInterval(() => {
								this.firstTime--
								if (this.firstTime === 0) {
									clearInterval(intTime)
									this.firstShow = false
									uni.showTabBar()
								}
							}, 1000);
						}
						uni.hideTabBar()
					}
				})
			},
			address() {
				const params = {
					map: 'applet_get_area'
				}
				this.$Request({
					method: 'GET',
					data: params
				}).then(res => {
					if (res.data.ec == 200) {
						let address = uni.getStorageSync('address')
						res.data.data.map(item => {
							if (item.name == address) {
								uni.setStorageSync('adcode', item.adcode)
								this.gethomedata()
							}
						})
					} else {

					}
				})

			},
			gethomedata() {
				this.items = []
				const params = {
					map: 'applet_custom_tpl_base'
				}
				this.$Request({
					method: 'GET',
					data: params
				}).then(res => {
					if (res.data.ec == 200) {
						console.log(res)
						uni.stopPullDownRefresh()
						this.items = res.data.data.templateData
					} else {
						uni.stopPullDownRefresh()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.firstBox {
		.firstImg {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
			z-index: 999999;
		}

		.firstImgTime {
			position: fixed;
			right: 30rpx;
			top: 80rpx;
			text-align: center;
			line-height: 50rpx;
			color: #FFFFFF;
			background: rgba(0, 0, 0, .5);
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
			z-index: 999999;
		}

		.firstNext {
			position: fixed;
			right: 5rpx;
			bottom: 10%;
			text-align: center;
			line-height: 50rpx;
			color: #FFFFFF;
			background: rgba(0, 0, 0, .5);
			width: 200rpx;
			height: 50rpx;
			border-radius: 100rpx;
			z-index: 999999;
		}
	}
</style>
